package main

import (
	"fmt"
	"math"
)

var res = math.MinInt32

func main() {
	var n, p int
	_, _ = fmt.Scan(&n, &p)

	items := make([][]int, n)
	for i := 0; i < n; i++ {
		items[i] = make([]int, 3)
		for j := 0; j < 3; j++ {
			_, _ = fmt.Scan(&items[i][j])
		}
	}

	f(items, 0, p, 0)
	fmt.Println(res)
}

func f(items [][]int, cp, mp, cm int) {
	for i := 0; i < len(items); i++ {
		if items[i][0] > 0 {
			items[i][0]--

			if cp+items[i][1] > mp {
				res = max(res, cm)
			} else if cp+items[i][1] == mp {
				res = max(res, cm+items[i][2])
			} else {
				f(items, cp+items[i][1], mp, cm+items[i][2])
			}

			items[i][0]++
		}
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}

	return b
}
